#ifndef _HEAD_H_
#define _HEAD_H_

#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include <sqlite3.h>
#include <stdlib.h>
#include <string.h>
#include "cJSON.h"
#include "MQTTClient.h"
#include "shmem.h"
#include <time.h>
//MQTT配置
#define CLIENTID "ExampleClientSub"
#define TOPIC_UP "/app/data/up"
#define TOPIC_DOWN "/app/data/down"
#define PAYLOAD "Hello World!"
#define QOS 1
#define TIMEOUT 10000L
char ADDRESS[128]="";
MQTTClient client;
MQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer;
MQTTClient_message pubmsg = MQTTClient_message_initializer;
MQTTClient_deliveryToken token;
int rc;
int ch;
//分析命令
int send_type; //上报命令 0-不上报，客户端主动采集；1-变化上报，即连续2次值不相等；2-周期上报
int ctl_type;  //控制命令
int send_time; //上报时间间隔
int time_falg;
//共享内存
union val_t {
    int b_val;   //bool类型存储空间
    int i_val;   //整形值存储空间
    float f_val; //浮点值存储空间
};
struct std_node
{
    int key;             //唯一键值
    int type;            //数据点类型
    int dev_type;        //数据点属于哪个设备，根据网关支持的设备自行定义
    union val_t old_val; //变化上报后需要更新旧值
    union val_t new_val; //从共享内存取出最新数据，放到new_val中
    int ret;             //默认为-1，采集成功后设置为0，采集失败再置-1
};
//消息队列
struct msgbuf
{
    long type; //必须有，表示消息的类型，赋值必须大于0
    int key;   //正文随意设置
    union val_t val;
};
//设备数
int mod_dev_num = 0;
int stm_dev_num = 0;
int *dev_num = NULL;
//for sqlite
sqlite3 *db;
char *errmsg = NULL;

#endif